package com.lgj.rocketmq.code;

import com.lgj.rocketmq.annotation.RocketMqConsumer;
import io.netty.util.internal.StringUtil;
import lombok.Data;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;

/**
 * @author: guangjie.liao
 * @since: 2023/9/19 21:38
 * @description: 消费者初始化配置
 */
@Data
public class Consumer {
    /**
     * 消费组
     */
    private String group;
    /**
     * broker实例
     */
    private String instanceName;
    /**
     * 消费模式
     */
    private MessageModel messageModel;
    /**
     * topic
     */
    private String topic;
    /**
     * 重试次数
     */
    private Integer maxReconsumeTimes;


    public static Consumer convert(RocketMqConsumer rocketMqConsumer){
        Consumer consumer = new Consumer();
        consumer.setGroup(rocketMqConsumer.group());
        consumer.setInstanceName(rocketMqConsumer.instanceName());
        consumer.setMessageModel(rocketMqConsumer.messageModel());
        String maxReconsumeTimes = rocketMqConsumer.maxReconsumeTimes();
        if (!StringUtil.isNullOrEmpty(maxReconsumeTimes)){
            consumer.setMaxReconsumeTimes(Integer.valueOf(maxReconsumeTimes));
        }
        return consumer;
    }
}
